import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

//import java.util.ArrayList;
//import java.util.StringTokenizer;
//import java.util.Scanner;

/*
Written by			Matrikel Number
Yannic Remmet			196983
Tobias Trabelsi			197112
Anna-Katharina Wickert	197122
*/


public class Caterpiller {
		public static void main(String args[]){ 
			String n = "The Fat Cat Smokes Crack";
			run(n);
	  } 

	  static int maxIndex;
	  static String[] feld;
	  static String permuts = "";
	  
	  static void run(String s){
		  StringTokenizer st = new StringTokenizer(s);
		  feld = new String[st.countTokens()];
		  for(int i = 0 ; i<feld.length; i++){
			  feld[i] = st.nextToken();
		  }
		  maxIndex = feld.length-1;
		  perm(feld, maxIndex);
		  out();
		  
	  }

	  static void result(String[] a){		//20 Coffee later...
		 for (int i=0; i<=maxIndex; i++)
			 permuts += a[i]+ " ";
	     	 permuts += "\n";

	  }

	  static void change(String[] a, int i, int j){
	     String ablage = a[i];
	     a[i] = a[j];
	     a[j] = ablage;
	  }

	  static void perm(String[] a, int endIndex){
	     if (endIndex==0){
	            result(a);
	     }
	     else { perm(a, endIndex-1);
	            for (int i=0; i<=endIndex-1; i++)
	            {  //System.out.println("i: " + i + " a[0]: " + a[0] + " a[1]: " + a[1] + " a[2]: " + a[2]);
	            	change(a, i, endIndex);
	            	//System.out.println("i: " + i + " a[0]: " + a[0] + " a[1]: " + a[1] + " a[2]: " + a[2]);
	               perm(a, endIndex-1);
	               //System.out.println("i: " + i + " a[0]: " + a[0] + " a[1]: " + a[1] + " a[2]: " + a[2]);
	               change(a, i, endIndex);
//<<<<<<< .mine
	            }
//=======
	               //System.out.println("i: " + i + " a[0]: " + a[0] + " a[1]: " + a[1] + " a[2]: " + a[2]);
	            } // for i
//>>>>>>> .r95
	          }
	  
	  
	  static void out(){	
		try {
			PrintWriter out = new PrintWriter(new FileWriter("cat.txt"));
			out.write(permuts);
			out.flush();
			out.close();
		} catch (IOException e){
			e.printStackTrace();
	
			}
	  }
	  }


	